//
//  ZYLAuthorTableView.m
//  Cartoon
//
//  Created by dllo on 15/7/15.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ZYLAuthorTableView.h"
#import "Define.h"
#import "ZYLAuthorTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "ZYLAuthorTopicModel.h"
@interface ZYLAuthorTableView ()
@property (nonatomic, retain) UIView *headerBackgroundView;
@property (nonatomic, retain) UIImageView *backgroundImageView;

@end

@implementation ZYLAuthorTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        [self createAuthorTableViewWithFrame:frame];
    }
    return self;
}


- (void)createAuthorTableViewWithFrame:(CGRect)frame
{
    self.delegate = self;
    self.dataSource = self;
    self.rowHeight = (SCREEN_WIDTH - 10) * 0.6;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *v = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)] autorelease];
    UILabel *l = [[[UILabel alloc] initWithFrame:CGRectMake(20, 10, SCREEN_WIDTH - 40, 20)] autorelease];
    l.text = @"TA的专题";
    [v addSubview:l];
    UIView *v1 = [[[UIView alloc] initWithFrame:CGRectMake(0, v.frame.size.height - 0.5, SCREEN_WIDTH, 0.5)] autorelease];
    v1.backgroundColor = [UIColor lightGrayColor];
    [v addSubview:v1];
    return v;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    NSLog(@"%ld", self.autorModel.authortopics.count);
    return self.autorModel.authortopics.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZYLAuthorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AuthorTable"];
    if (!cell) {
        cell = [[[ZYLAuthorTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"AuthorTable"] autorelease];
    }
    [cell.topicImageView sd_setImageWithURL:[NSURL URLWithString:[self.autorModel.authortopics[indexPath.row] topiccover_image_url]]];
    cell.topicTitle.text = [self.autorModel.authortopics[indexPath.row] topictitle];
    cell.topicIntro.text  = [self.autorModel.authortopics[indexPath.row] topicdescription];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSLog(@"%@", [self.autorModel.authortopics[indexPath.row] topictitle]);
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.block(scrollView.contentOffset.y);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}
@end
